﻿// ***********************************************************************
// Assembly         : AcceptanceTest
// Author           : yubao
// Created          : 07-29-2014
//
// Last Modified By : yubao
// Last Modified On : 07-29-2014
// ***********************************************************************
// <copyright file="Program.cs" company="www.cnblogs.com/dotcpp">
//     Copyright (c) www.cnblogs.com/dotcpp. All rights reserved.
// </copyright>
// <summary>
//验收测试
//模拟多客户端测试
//模拟数据收发
//</summary>
// ***********************************************************************
using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace AcceptanceTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            while (true)
            {
            Connect("192.168.0.110", "client data--" + i++);
            }


          //  DataAdhereTest("192.168.0.110", "fffffffffffffffffffffff+" + DateTime.Now);
        }

        //连接测试
        static void Connect(String server, String message)
        {
            try
            {
                Int32 port = 8080;
                TcpClient client = new TcpClient(server, port);
                Byte[] data = Encoding.ASCII.GetBytes(message);
                NetworkStream stream = client.GetStream();
                stream.Write(data, 0, data.Length);
                Console.WriteLine("Sent: {0}", message);
                stream.Close();
                client.Close();
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("ArgumentNullException: {0}", e);
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }
        }

        //粘包测试
        static void DataAdhereTest(String server, String message)
        {
            Int32 port = 8080;
            TcpClient client = new TcpClient(server, port);
            Byte[] data = Encoding.ASCII.GetBytes(message);
            NetworkStream stream = client.GetStream();
            while (true)
            {
                // Send the message to the connected TcpServer.
                stream.Write(data, 0, data.Length);
                Console.WriteLine("Sent: {0}", message);
                Thread.Sleep(500);
            }
        }
    }
}
